package com.alkaid.manga.controller;

import com.alkaid.commons.controller.BaseController;
import com.alkaid.commons.entity.AnimePageEntity;
import com.alkaid.commons.entity.Manga;
import com.alkaid.commons.utils.JsonResult;
import com.alkaid.manga.service.MangaService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Kylin
 */
@RestController
@RequestMapping("api/manga")
public class MangaController extends BaseController {

    private MangaService mangaService;

    @Autowired
    public void setNovelService(MangaService mangaService) {
        this.mangaService = mangaService;
    }

    /**
     * 热度排行
     *
     * @param num the num
     * @return the hot list
     */
    @GetMapping("/hot_list/{num}")
    public JsonResult<List<Manga>> getHotList(@PathVariable Integer num) {
        List<Manga> lists = mangaService.getHotList(num);
        return new JsonResult<>(200, lists, "success");
    }

    @PostMapping("/all")
    public JsonResult<PageInfo<Manga>> getAll(@Validated AnimePageEntity page) {
        PageInfo<Manga> pageInfo = mangaService.getAll(page);
        return new JsonResult<>(200, pageInfo, "success");
    }

    /**
     * 播放量排行
     *
     * @param num the num
     * @return the count list
     */
    @GetMapping("/count_list/{num}")
    public JsonResult<List<Manga>> getCountList(@PathVariable int num) {
        List<Manga> lists = mangaService.getCountList(num);
        return new JsonResult<>(200, lists, "success");
    }

    @GetMapping("/play/ss/{id}")
    public JsonResult<Manga> getMangaPlayByNovelId(@PathVariable Integer id) {
        Manga manga = mangaService.getMangaWithDetailsPlayByMangaId(id);
        return new JsonResult<>(200, manga, "success");
    }
}
